package com.lx.javasunmmrize.XMLJsonUtils;

import org.junit.Test;

public class StaxonUtilsTest {

    @Test
    public void test_json2xml() {
        String json = "{\n" +
                "\t\"Response\" : {\n" +
                "\t\t\"CustID\" : 1300000428,\n" +
                "\t\t\"CompID\" : 1100000324,\n" +
                "\t\t\"Items\" : {\n" +
                "\t\t\t\"Item\" : [ {\n" +
                "\t\t\t\t\"Sku_ProductNo\" : \"sku_0004\",\n" +
                "\t\t\t\t\"Wms_Code\" : 1700386977,\n" +
                "\t\t\t\t\"Sku_Response\" : \"T\",\n" +
                "\t\t\t\t\"Sku_Reason\" : null\n" +
                "\t\t\t}, {\n" +
                "\t\t\t\t\"Sku_ProductNo\" : \"0005\",\n" +
                "\t\t\t\t\"Wms_Code\" : 1700386978,\n" +
                "\t\t\t\t\"Sku_Response\" : \"T\",\n" +
                "\t\t\t\t\"Sku_Reason\" : null\n" +
                "\t\t\t} ]\n" +
                "\t\t},\n" +
                "\t\t\"xml\" : {\n" +
                "\t\t\t\"Item\" : [ {\n" +
                "\t\t\t\t\"Sku_ProductNo\" : \"sku_0004\",\n" +
                "\t\t\t\t\"Wms_Code\" : {\n" +
                "\t\t\t\t\t\"@tx\" : \"js\",\n" +
                "\t\t\t\t\t\"$\" : 1700386977\n" +
                "\t\t\t\t},\n" +

                "\t\t\t\t\"Sku_Response\" : \"T\",\n" +
                "\t\t\t\t\"Sku_Reason\" : null\n" +
                "\t\t\t}, {\n" +
                "\t\t\t\t\"Sku_ProductNo\" : \"0005\",\n" +
                "\t\t\t\t\"Wms_Code\" : 1700386978,\n" +
                "\t\t\t\t\"Sku_Response\" : \"T\",\n" +
                "\t\t\t\t\"Sku_Reason\" : null\n" +
                "\t\t\t} ]\n" +
                "\t\t}\n" +
                "\t}\n" +
                "}\n";
        String xml = StaxonUtils.json2xml(json);

//        File file = new File("test.xml");

        System.out.println(xml);
    }

    @Test
    public void test_xml2json() {
        String xml = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n" +
                "<Response>\n" +
                "\t<CustID>1300000428</CustID>\n" +
                "\t<CompID>1100000324</CompID>\n" +
                "\t<Items>\n" +
                "\t\t<Item>\n" +
                "\t\t\t<Sku_ProductNo>sku_0004</Sku_ProductNo>\n" +
                "\t\t\t<Wms_Code>1700386977</Wms_Code>\n" +
                "\t\t\t<Sku_Response>T</Sku_Response>\n" +
                "\t\t\t<Sku_Reason></Sku_Reason>\n" +
                "\t\t</Item>\n" +
                "\t\t<Item>\n" +
                "\t\t\t<Sku_ProductNo>0005</Sku_ProductNo>\n" +
                "\t\t\t<Wms_Code>1700386978</Wms_Code>\n" +
                "\t\t\t<Sku_Response>T</Sku_Response>\n" +
                "\t\t\t<Sku_Reason></Sku_Reason>\n" +
                "\t\t</Item>\n" +
                "\t</Items>\n" +
                "\t<xml>\n" +
                "\t\t<Item>\n" +
                "\t\t\t<Sku_ProductNo>sku_0004</Sku_ProductNo>\n" +
                "\t\t\t<Wms_Code tx=\"js\">1700386977</Wms_Code>\n" +
                "\t\t\t<Sku_Response>T</Sku_Response>\n" +
                "\t\t\t<Sku_Reason></Sku_Reason>\n" +
                "\t\t</Item>\n" +
                "\t\t<Item>\n" +
                "\t\t\t<Sku_ProductNo>0005</Sku_ProductNo>\n" +
                "\t\t\t<Wms_Code>1700386978</Wms_Code>\n" +
                "\t\t\t<Sku_Response>T</Sku_Response>\n" +
                "\t\t\t<Sku_Reason></Sku_Reason>\n" +
                "\t\t</Item>\n" +
                "\t</xml>\n" +
                "</Response>";
        String json = StaxonUtils.xml2json(xml);
//        json.replace("\\s","");
        json.replace("\\n","");
        System.out.println(json);
    }


}